package com.zxy.controller;

import com.zxy.common.result.Result;
import com.zxy.pojo.dto.ActivityListQuery;
import com.zxy.pojo.entity.Activity;
import com.zxy.pojo.vo.ActivityCreateVO;
import com.zxy.pojo.vo.ActivityDictResponseVO;
import com.zxy.pojo.vo.ActivityPageVO;
import com.zxy.pojo.vo.ActivityResponseVO;
import com.zxy.service.ActivityService;
import com.zxy.util.OperLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 活动管理Controller（匹配接口路径/clues/activity/list）
 */
@RestController
@RequestMapping
@Validated // 开启参数校验
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 活动列表分页查询接口
     * 路径：GET /clues/activity/list
     */
    @OperLog(title = "活动列表分页查询", businessType = 0, saveParams = true)
    @GetMapping("/clues/activity/list")
    public ActivityPageVO getActivityList(@Validated ActivityListQuery query) {
        return activityService.getActivityList(query);
    }

    /**
     * 通用字典类型查询接口
     */
    @OperLog(title = "活动字典数据查询", businessType = 0, saveParams = true)
    @GetMapping("/system/dict/data/type/{dictType}")
    public ActivityDictResponseVO getDictList(
            @PathVariable("dictType") String dictType
    ) {
        return activityService.getDictListByType(dictType);
    }


    /**
     * 活动创建接口
     * 路径：POST /clues/activity
     */
    @OperLog(title = "创建活动", businessType = 1, saveParams = true, saveResult = true)
    @PostMapping("/clues/activity")
    public ActivityResponseVO createActivity(
            @Validated @RequestBody ActivityCreateVO createVO
    ) {
        return activityService.createActivity(createVO);
    }

    /**
     * 活动详情查询接口
     */
    @OperLog(title = "查询活动详情", businessType = 0, saveParams = true)
    @GetMapping("/clues/activity/{id}")
    public Result<Activity> getActivityDetail(
            @PathVariable("id") Long id
    ) {
        return Result.success(activityService.getById(id));
    }

    /**
     * 活动删除接口
     */
    @OperLog(title = "删除活动", businessType = 3, saveParams = true, saveResult = true)
    @DeleteMapping("/clues/activity/{id}")
    public Result<String> deleteActivity(
            @PathVariable("id") Long id
    ) {
        return activityService.removeById(id) ?
                Result.success("删除成功") :
                Result.error("删除失败");
    }

    /**
     * 活动修改接口
     */
    @OperLog(title = "修改活动", businessType = 2, saveParams = true, saveResult = true)
    @PutMapping("/clues/activity")
    public Result updateActivity(@RequestBody Activity activity){
        activityService.updateById(activity);
        return Result.success();
    }
}
